Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-collection

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-collection

Break objects into pieces and control them from those pieces.

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
32
decreased by-37.25%
Maintainers
1
Weekly downloads
 
Created
Source

Javascript object collection.

NPM | YARN

Built from Lodash's object functions api.

so instead of _.extend(obj, data) you do data.extend({}).

All lodash helpers that mutates object returns this

When to use ObjectCollection.

ObjectCollection is best used when accessing large objects e.g Api data, Your config object e.t.c

Usage

const Obj = require("object-collection");

// Creates empty object
let data = new Obj();
// => {}

const User = {name: "John", age: 32, gender: "male"};

// Use already existing object.
const user = new Obj(User);
// => {name: "John", age: 32, gender: 'male'}

// OR Use is a static helper to create new collection instance
const user = Obj.use(User);
// => {name: "John", age: 32, gender: "male"}


user.has("name")
// => true

user.pick(['name', 'age']);
// => {name: "John", age: 32}


user.set({hobbies: ['code', 'eat', 'sleep']});
// => {name: "John", age: 32, gender: "male", hobbies: ['code', 'eat', 'sleep']}

You get the idea right? All object helpers in lodash are available on this

We also added a few more helpers. e.g

If a path in your object holds an object we can access it as a collection using .path helper

// Add contact_details to User
user.set('contact_details', {
    address: 'No 1 Astro World', 
    phone: '+123456789',
    country: 'US',
});

user.path("contact_details");
// Returns message value as a collection

user.get("contact_details.address");
//OR
user.path("contact_details").get('address');
// => No 1 Astro World

user.path("contact_details").pick(['phone', 'US'])
// => {phone: '+123456789', country: 'US'}
Full Docs coming soon

Keywords

FAQs

Package last updated on 06 Apr 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc